//
//  ZZNavViewController.swift
//  web
//
//  Created by 张卓 on 2017/1/16.
//  Copyright © 2017年 ZZ. All rights reserved.
//

import UIKit

class ZZNavViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        //添加手势点击 侧滑
        interactivePopGestureRecognizer?.delegate = self
        
    }
    //将要接收手势点击 解决侧滑BUG
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        if childViewControllers.count == 1{
            return false
        }else {
            return true
        }
        
        
    }
    

    //重写 PUSH  方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
        
            var title = "返回"
            if childViewControllers.count == 1{

                title = childViewControllers.first?.title ?? ""
                
                //隐藏tabbar
                viewController.hidesBottomBarWhenPushed = true
            }
            //设置左侧按钮
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(image: nil, title: title, target: self, action: #selector(leftBntClick))
        
        }
        super.pushViewController(viewController, animated: true)
    }
    //点击左上角按钮
    @objc private func leftBntClick() {
        
        _ = popViewController(animated: true)
        
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
